From 9f4330d6c17675273e7037971ce24beb949376fd Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Wed, 27 Jul 2016 11:22:06 -0400 Subject: [PATCH] Print a more useful error message when the target binary can't be removed. This happens sometimes on Windows if the target is still running, and right now cargo prints a very cryptic message: ``` $ cargo build Compiling sccache v0.1.0 (file:///C:/build/sccache2) An unknown error occurred ``` With this patch we get a much more useful error: ``` $ ../cargo/target/debug/cargo build Compiling sccache v0.1.0 (file:///C:/build/sccache2) error: Could not remove file: c:\build\sccache2\target\debug\sccache.exe. To learn more, run the command again with --verbose. ``` --- src/cargo/ops/cargo_rustc/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index bffb0b63f..7dfa8ff45 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -258,7 +258,9 @@ fn rustc(cx: &mut Context, unit: &Unit) -> CargoResult { for &(ref filename, _linkable) in filenames.iter() { let dst = root.join(filename); if fs::metadata(&dst).is_ok() { - try!(fs::remove_file(&dst)); + try!(fs::remove_file(&dst).chain_error(|| { + human(format!("Could not remove file: {}.", dst.display())) + })); } } -- 2.30.2